package com.bookmarket.service.impl;

import com.bookmarket.dao.LLBookDao;
import com.bookmarket.entity.Book;
import com.bookmarket.entity.Btype;
import com.bookmarket.entity.Stype;
import com.bookmarket.service.LLBookService;
import com.github.pagehelper.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * LLBookServiceImpl
 *
 * @author 李亮
 * @date 2017/12/26
 */
@Service("/bookService")
public class LLBookServiceImpl implements LLBookService {
    @Resource
    private LLBookDao bookdao;



    @Override
     public Map getall(Map<String, Object> cond) {
        Page page = new Page();
        page.setTotal(bookdao.getcount(cond));
        int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));
        page.setPageSize(pageSize);
        int curPageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));
        page.setPageNum(curPageNum);

        int zong=  (int) (page.getTotal() / pageSize + (page.getTotal() % pageSize == 0 ? 0 : 1));
        List<Book> list = bookdao.getlist(cond);


        Map map = new HashMap();
        map.put("list",list);
        map.put("totlpage",zong);
        return map;
    }
    public List<Stype> getstype(int id){
        List<Stype> list=bookdao.getastype(id);

        return bookdao.getastype(id);
    }

    public Stype getstype1(int id){
      return  bookdao.getstype1(id);
    }
    public List<Btype> getallbtype(){
        return bookdao.getallbtype();
    }
    public Book getbook(int id){
        return  bookdao.getbook1(id);
    }
    public boolean update (Book book){

        return  bookdao.update(book);
    }
    public boolean delet(int id){
        return  bookdao.delet(id);
    }
    public void updat1(Book book){
         bookdao.updat1(book);
    }

    @Override
    public List<Stype> getAllStype() {
        return bookdao.getAllStype();
    }

    public LLBookDao getBookdao() {
        return bookdao;
    }

    public void setBookdao(LLBookDao bookdao) {
        this.bookdao = bookdao;
    }
}